package com.seven.monior;

import android.app.ActivityManager;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.seven.monior.AppInfo.Global;

public class monitor extends TabActivity implements OnTabChangeListener {
	/** Called when the activity is first created. */
	private Intent intent;
	private TabHost tabHost;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Resources res = getResources(); // Resource object to get Drawables
		// The activity TabHost
		setTitle("Monitor " + Global.VER);

		Global.pm = this.getPackageManager();
		Global.am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
		Global.cm = (ConnectivityManager) this
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		Global.mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

		try {

			tabHost = getTabHost();

			TabHost.TabSpec spec; // Resusable TabSpec for each tab

			// Create an Intent to launch an Activity for the tab (to be reused)

			intent = new Intent().setClass(this, Apps.class);
			// Initialize a TabSpec for each tab and add it to the TabHost

			// spec = tabHost
			// .newTabSpec("apps")
			// .setIndicator("Apps",
			// res.getDrawable(R.drawable.ic_tab_apps))
			// .setContent(intent);
			// tabHost.addTab(spec);

			// Do the same for the other tabs
			intent = new Intent().setClass(this, SystemApps.class);
			spec = tabHost
					.newTabSpec("systemapps")
					.setIndicator("SystemApps",
							res.getDrawable(R.drawable.ic_tab_tasks))
					.setContent(intent);
			tabHost.addTab(spec);

			intent = new Intent().setClass(this, Tasks.class);
			spec = tabHost
					.newTabSpec("tasks")
					.setIndicator("3rdPartyApps",
							res.getDrawable(R.drawable.ic_tab_tasks))
					.setContent(intent);
			tabHost.addTab(spec);

			tabHost.setOnTabChangedListener(this);

			tabHost.setCurrentTab(1);

			// start service
			startService(new Intent(this, MonitorService.class));

			// {
			//
			// List<RunningAppProcessInfo> list = Global.am
			// .getRunningAppProcesses();
			// for (RunningAppProcessInfo rInfo : list) {
			// ProcessState pState = new ProcessState(rInfo.pid);
			// Log.d("CPUSTIME " + rInfo.pid,
			// String.valueOf(pState.getCpuSTime()));
			// Log.i("CPUUTIME " + rInfo.pid,
			// String.valueOf(pState.getCpuUTime()));
			// }
			//
			// }
		} catch (Exception ex) {
			ex.printStackTrace();
			Log.d("EXCEPTION", ex.getMessage());
		}
	}

	@Override
	protected void onStart() {
		MonitorService.Monitor_Visible = true;

		super.onStart();
	}

	@Override
	protected void onStop() {
		MonitorService.Monitor_Visible = false;

		super.onStop();
	}

	@Override
	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		// Reusable Intent for each tab

	}

}